﻿namespace AutoFakesTest
{
    using System;
    using System.IO;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;
    using AutoFakes;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class DependencyNotStubbedExceptionTests
    {
        [TestMethod]
        public void CtorMayBeInvokedWoArgs()
        {
            // Act
            var target = new DependencyNotStubbedException();

            // Assert
            Assert.IsNotNull(target);
        }

        [TestMethod]
        public void CtorMayBeInvokedWMessageAndInnerException()
        {
            // Act
            var innerException = new Exception();
            var target = new DependencyNotStubbedException("foo", innerException);

            // Assert
            Assert.IsNotNull(target);
        }

        [TestMethod]
        public void ExceptionCanBeSerializedAndDeserializedCorrectly()
        {
            // Arrange
            var target = new DependencyNotStubbedException();
            var memoryStream = new MemoryStream();
            var binaryFormatter = new BinaryFormatter();
            try
            {
                binaryFormatter.Serialize(memoryStream, target);

                IFormatter formatter = new BinaryFormatter();
                memoryStream.Position = 0;

                // Act
                var result = (DependencyNotStubbedException)formatter.Deserialize(memoryStream);

                // Assert
                Assert.IsNotNull(result);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
    }
}
